import path from 'node:path';

import react from '@vitejs/plugin-react';
import { defineConfig } from 'vite';
import { viteMockServe } from 'vite-plugin-mock';

// https://vite.dev/config/
export default defineConfig(({ mode }) => {
    const isMock = mode === 'mock';

    return {
        mode: process.env.NODE_ENV,
        plugins: [
            react(),
            viteMockServe({
                mockPath: path.resolve(__dirname, './mock'),
                enable: isMock,
            }),
        ],
        resolve: {
            alias: {
                '@': path.resolve(__dirname, './src'),
                '@music/encrypt-fetch': path.resolve(
                    __dirname,
                    '../../node_modules/@music/encrypt-fetch/lib/index.js'
                ),
            },
        },
        define: {
            'process.env': {
                NODE_ENV: process.env.NODE_ENV,
            },
        },
        css: {
            preprocessorOptions: {
                scss: {
                    quietDeps: true,
                },
            },
        },
        build: {
            outDir: 'dist',
            rollupOptions: {
                output: {
                    manualChunks: () => {
                        return null;
                    },
                },
            },
        },
        server: {
            proxy: {},
        },
    };
});
